package com.lingo.dingrobotutils.model.msgBuilder;

import com.dingtalk.api.request.OapiRobotSendRequest;

import java.util.List;

/**
 * @file: com.lingo.dingRobot.common.model.msgBuilder.DingTextMsgBuilder
 * @Description: 封装 Text 消息类型
 * @author: lingo
 * @version: v1.0
 * @date: 2020/3/23 9:37
 * @Company: www.xyb2b.com
 */

public class DingTextMsgBuilder extends MyDingMsgBuilder {

    private final OapiRobotSendRequest.Text text = new OapiRobotSendRequest.Text();
    private final OapiRobotSendRequest.At at = new OapiRobotSendRequest.At();

    public DingTextMsgBuilder() {
        this.request.setMsgtype("text");
        this.request.setText(text);
    }

    public DingTextMsgBuilder setContent(String content){
        if (content != null && !content.isEmpty()){
            this.text.setContent(content);
        }
        return this;
    }

    public DingTextMsgBuilder at(List<String> mobileList){
        return at(mobileList,false);
    }

    public DingTextMsgBuilder at(List<String> mobileList,boolean isAtAll){
        if (mobileList != null && !mobileList.isEmpty()) {
            at.setAtMobiles(mobileList);
        }
        at.setIsAtAll(isAtAll ? "true" : "false");
        return this;
    }

    @Override
    public OapiRobotSendRequest build() {
        this.request.setText(text);
        this.request.setAt(at);
        return request;
    }
}
